package com.boang.obj;

import java.io.*;

/*
    @author:sa
    @date:2024/12/12 16:18
*/
public class ObjInputOutputDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        w();
        r();
    }

    private static void r() throws IOException, ClassNotFoundException {
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("fs.obj"));
        Student student = (Student) objectInputStream.readObject();
        System.out.println(student.name);
        System.out.println(student.age);
    }

    private static void w() throws IOException {
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("fs.obj"));
        Student student = new Student("zhangsan", 20);
        objectOutputStream.writeObject(student);
    }
}